package com.algorithm.ch1.yjx.string;

/**
 * @author yuanjianxin
 * @date 2018/8/15 16:42
 * 和反转数值一个思想
 */
public class ReverseString {
    public static void main(String[] args) {
        String str = "A man, a plan, a canal: Panama";
        System.out.println(reverseString(str));
    }


    public static String reverseString(String s) {
        char[] chars = s.toCharArray();
        int start = 0;
        int end = chars.length - 1;
        char temp;
        while (start < end) {
            temp = chars[start];
            chars[start] = chars[end];
            chars[end] = temp;
            start++;
            end--;
        }
        return new String(chars);
    }
}
